import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class text {
    public static void main(String[] args){
        //ArrayList相关的遍历方法；
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        int ret=arrayList.size();
        //for循环；
        for(int i=0;i<ret;i++){
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        //foreach循环；
        for(Integer x :arrayList){
            System.out.print(x+" ");
        }
        System.out.println();
        //迭代器；
        Iterator<Integer> it= arrayList.iterator();
        while(it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();
        ListIterator<Integer> itt=arrayList.listIterator(arrayList.size());
        while(itt.hasPrevious()){
            System.out.print(itt.previous()+" ");//从后往前进行遍历；
        }
        System.out.println();
    }


}
